package com.zzz.framework.config.mybatis;

import com.mybatisflex.annotation.InsertListener;
import com.zzz.framework.model.BaseDO;
import com.zzz.framework.util.LoginInfoUtil;

import java.time.LocalDateTime;

public class MyInsertListener implements InsertListener {

    @Override
    public void onInsert(Object entity) {
        if (entity instanceof BaseDO) {
            //设置 account 被新增时的一些默认数据
            BaseDO baseDO = (BaseDO)entity;
            String loginId = LoginInfoUtil.getLoginId().toString();
            baseDO.setCreateTime(LocalDateTime.now());
            baseDO.setCreator(loginId);
            baseDO.setUpdateTime(LocalDateTime.now());
            baseDO.setUpdater(loginId);

            //多租户的场景下，设置当前 租户 ID ..
//            baseDO.setTenantId("....");

        }

    }
}
